/**
 * 传播力-内容列表
 */
;
(function($, window, document, undefined) {
    var SpreadContent = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons'
        };
        this.options = $.extend({}, this.defaults, opts);
    }

    SpreadContent.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == 'true') {
                return me;
            }

            me.initAjaxTable();
            me.bindEvents();


            el.attr('data-initialized', 'true');
            return me;
        },


        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;

        },

        /**
         * 初始化ajax table
         * @return {[type]} [description]
         */
        initAjaxTable: function() {
            var me = this,
                el = me.el,
                option;

            var option = {
                'columnDefs': [{
                    "targets": [0],
                    "data": "id",
                    "render": function(data, type, full) {
                        return "<input type=\"checkbox\" name=\"id[]\" value=\"" + data + "\">";
                    }
                }, {
                    "targets": [1],
                    "orderable": false,
                    "data": "job_company",
                    "name": "job_company"
                }, {
                    "targets": [2],
                    "orderable": false,
                    "data": "job_post",
                    "name": "job_post"
                }, {
                    "targets": [3],
                    "data": "start_time",
                    "name": "start_time"
                }, {
                    "targets": [4],
                    "orderable": false,
                    "data": "job_place",
                    "name": "job_place",
                }, {
                    "targets": [5],
                    "data": "id",
                    "orderable": false,
                    "render": function(data, type, full) {
                        return '<a href="/admin/jobs/' + data + '/edit" class="btn default btn-xs purple"><i class="fa fa-edit"></i> 编辑</a><a href="/admin/jobs/' + data + '" class="btn default btn-xs black" data-method="delete" data-confirm="确定删除此条记录吗？"><i class="fa fa-trash-o"></i> 删除</a>';
                    }
                }],
            }


            //init table-managed
            TableAjax.init(option || {});
        }
    }


    $.fn.SpreadContent = function(opts) {
        var me = this,
            el = me.el,
            comSpreadContent;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comSpreadContent = new SpreadContent(this, opts);
        }

        return comSpreadContent.init();
    }
})(jQuery, window, document);
